From a58f6bb65cb5329c49f0f5b75dc43d32f12ad6a5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 1 Oct 2016 13:31:12 +0300 Subject: [PATCH] Rename message-format flag to json --- src/bin/bench.rs | 11 ++++------- src/bin/build.rs | 12 ++++-------- src/bin/doc.rs | 11 ++++------- src/bin/run.rs | 11 ++++------- src/bin/rustc.rs | 12 ++++-------- src/bin/rustdoc.rs | 11 ++++------- src/bin/test.rs | 11 ++++------- src/cargo/lib.rs | 3 +-- src/cargo/ops/cargo_compile.rs | 13 +------------ tests/build.rs | 8 ++++---- 10 files changed, 34 insertions(+), 69 deletions(-) diff --git a/src/bin/bench.rs b/src/bin/bench.rs index 521c87c2f..d9abefe40 100644 --- a/src/bin/bench.rs +++ b/src/bin/bench.rs @@ -1,5 +1,5 @@ use cargo::core::Workspace; -use cargo::ops; +use cargo::ops::{self, MessageFormat}; use cargo::util::{CliResult, CliError, Human, Config, human}; use cargo::util::important_paths::{find_root_manifest_for_wd}; @@ -16,7 +16,7 @@ pub struct Options { flag_verbose: u32, flag_quiet: Option, flag_color: Option, - flag_message_format: Option, + flag_message_format: MessageFormat, flag_lib: bool, flag_bin: Vec, flag_example: Vec, @@ -51,7 +51,7 @@ Options: -v, --verbose ... Use verbose output -q, --quiet No output printed to stdout --color WHEN Coloring: auto, always, never - --message-format FMT Error format: human, json-v1 + --message-format FMT Error format: human, json [default: human] --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date @@ -77,9 +77,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { &options.flag_color, options.flag_frozen, options.flag_locked)); - let message_format = try!(ops::MessageFormat::from_option( - &options.flag_message_format - )); let ops = ops::TestOptions { no_run: options.flag_no_run, no_fail_fast: false, @@ -100,7 +97,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { &options.flag_test, &options.flag_example, &options.flag_bench), - message_format: message_format, + message_format: options.flag_message_format, target_rustdoc_args: None, target_rustc_args: None, }, diff --git a/src/bin/build.rs b/src/bin/build.rs index c4619f541..0357fe080 100644 --- a/src/bin/build.rs +++ b/src/bin/build.rs @@ -1,8 +1,7 @@ use std::env; use cargo::core::Workspace; -use cargo::ops::CompileOptions; -use cargo::ops; +use cargo::ops::{self, CompileOptions, MessageFormat}; use cargo::util::important_paths::{find_root_manifest_for_wd}; use cargo::util::{CliResult, Config}; @@ -18,7 +17,7 @@ pub struct Options { flag_verbose: u32, flag_quiet: Option, flag_color: Option, - flag_message_format: Option, + flag_message_format: MessageFormat, flag_release: bool, flag_lib: bool, flag_bin: Vec, @@ -53,7 +52,7 @@ Options: -v, --verbose ... Use verbose output -q, --quiet No output printed to stdout --color WHEN Coloring: auto, always, never - --message-format FMT Error format: human, json-v1 + --message-format FMT Error format: human, json [default: human] --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date @@ -75,9 +74,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { &options.flag_color, options.flag_frozen, options.flag_locked)); - let message_format = try!(ops::MessageFormat::from_option( - &options.flag_message_format - )); let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())); @@ -97,7 +93,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { &options.flag_test, &options.flag_example, &options.flag_bench), - message_format: message_format, + message_format: options.flag_message_format, target_rustdoc_args: None, target_rustc_args: None, }; diff --git a/src/bin/doc.rs b/src/bin/doc.rs index 83431ef66..c1841c20a 100644 --- a/src/bin/doc.rs +++ b/src/bin/doc.rs @@ -1,5 +1,5 @@ use cargo::core::Workspace; -use cargo::ops; +use cargo::ops::{self, MessageFormat}; use cargo::util::{CliResult, Config}; use cargo::util::important_paths::{find_root_manifest_for_wd}; @@ -17,7 +17,7 @@ pub struct Options { flag_verbose: u32, flag_quiet: Option, flag_color: Option, - flag_message_format: Option, + flag_message_format: MessageFormat, flag_package: Vec, flag_lib: bool, flag_bin: Vec, @@ -48,7 +48,7 @@ Options: -v, --verbose ... Use verbose output -q, --quiet No output printed to stdout --color WHEN Coloring: auto, always, never - --message-format FMT Error format: human, json-v1 + --message-format FMT Error format: human, json [default: human] --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date @@ -67,9 +67,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { &options.flag_color, options.flag_frozen, options.flag_locked)); - let message_format = try!(ops::MessageFormat::from_option( - &options.flag_message_format - )); let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())); @@ -90,7 +87,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { &empty, &empty, &empty), - message_format: message_format, + message_format: options.flag_message_format, release: options.flag_release, mode: ops::CompileMode::Doc { deps: !options.flag_no_deps, diff --git a/src/bin/run.rs b/src/bin/run.rs index 4b03b53bc..f5055b5eb 100644 --- a/src/bin/run.rs +++ b/src/bin/run.rs @@ -1,5 +1,5 @@ use cargo::core::Workspace; -use cargo::ops; +use cargo::ops::{self, MessageFormat}; use cargo::util::{CliResult, CliError, Config, Human}; use cargo::util::important_paths::{find_root_manifest_for_wd}; @@ -16,7 +16,7 @@ pub struct Options { flag_verbose: u32, flag_quiet: Option, flag_color: Option, - flag_message_format: Option, + flag_message_format: MessageFormat, flag_release: bool, flag_frozen: bool, flag_locked: bool, @@ -43,7 +43,7 @@ Options: -v, --verbose ... Use verbose output -q, --quiet No output printed to stdout --color WHEN Coloring: auto, always, never - --message-format FMT Error format: human, json-v1 + --message-format FMT Error format: human, json [default: human] --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date @@ -63,9 +63,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { &options.flag_color, options.flag_frozen, options.flag_locked)); - let message_format = try!(ops::MessageFormat::from_option( - &options.flag_message_format - )); let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())); @@ -96,7 +93,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { bins: &bins, examples: &examples, } }, - message_format: message_format, + message_format: options.flag_message_format, target_rustdoc_args: None, target_rustc_args: None, }; diff --git a/src/bin/rustc.rs b/src/bin/rustc.rs index 2743c3669..fa9334f5b 100644 --- a/src/bin/rustc.rs +++ b/src/bin/rustc.rs @@ -1,8 +1,7 @@ use std::env; use cargo::core::Workspace; -use cargo::ops::{CompileOptions, CompileMode}; -use cargo::ops; +use cargo::ops::{self, CompileOptions, CompileMode, MessageFormat}; use cargo::util::important_paths::{find_root_manifest_for_wd}; use cargo::util::{CliResult, CliError, Config, human}; @@ -19,7 +18,7 @@ pub struct Options { flag_verbose: u32, flag_quiet: Option, flag_color: Option, - flag_message_format: Option, + flag_message_format: MessageFormat, flag_release: bool, flag_lib: bool, flag_bin: Vec, @@ -56,7 +55,7 @@ Options: -v, --verbose ... Use verbose output -q, --quiet No output printed to stdout --color WHEN Coloring: auto, always, never - --message-format FMT Error format: human, json-v1 + --message-format FMT Error format: human, json [default: human] --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date @@ -82,9 +81,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { &options.flag_color, options.flag_frozen, options.flag_locked)); - let message_format = try!(ops::MessageFormat::from_option( - &options.flag_message_format - )); let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())); @@ -115,7 +111,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { &options.flag_test, &options.flag_example, &options.flag_bench), - message_format: message_format, + message_format: options.flag_message_format, target_rustdoc_args: None, target_rustc_args: options.arg_opts.as_ref().map(|a| &a[..]), }; diff --git a/src/bin/rustdoc.rs b/src/bin/rustdoc.rs index 79e368090..587046200 100644 --- a/src/bin/rustdoc.rs +++ b/src/bin/rustdoc.rs @@ -1,5 +1,5 @@ use cargo::core::Workspace; -use cargo::ops; +use cargo::ops::{self, MessageFormat}; use cargo::util::{CliResult, Config}; use cargo::util::important_paths::{find_root_manifest_for_wd}; @@ -17,7 +17,7 @@ pub struct Options { flag_release: bool, flag_quiet: Option, flag_color: Option, - flag_message_format: Option, + flag_message_format: MessageFormat, flag_package: Option, flag_lib: bool, flag_bin: Vec, @@ -53,7 +53,7 @@ Options: -v, --verbose ... Use verbose output -q, --quiet No output printed to stdout --color WHEN Coloring: auto, always, never - --message-format FMT Error format: human, json-v1 + --message-format FMT Error format: human, json [default: human] --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date @@ -76,9 +76,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { &options.flag_color, options.flag_frozen, options.flag_locked)); - let message_format = try!(ops::MessageFormat::from_option( - &options.flag_message_format - )); let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())); @@ -100,7 +97,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { &options.flag_test, &options.flag_example, &options.flag_bench), - message_format: message_format, + message_format: options.flag_message_format, mode: ops::CompileMode::Doc { deps: false }, target_rustdoc_args: Some(&options.arg_opts), target_rustc_args: None, diff --git a/src/bin/test.rs b/src/bin/test.rs index a2f1f5f12..410c0a2c4 100644 --- a/src/bin/test.rs +++ b/src/bin/test.rs @@ -1,5 +1,5 @@ use cargo::core::Workspace; -use cargo::ops; +use cargo::ops::{self, MessageFormat}; use cargo::util::{CliResult, CliError, Human, human, Config}; use cargo::util::important_paths::{find_root_manifest_for_wd}; @@ -23,7 +23,7 @@ pub struct Options { flag_verbose: u32, flag_quiet: Option, flag_color: Option, - flag_message_format: Option, + flag_message_format: MessageFormat, flag_release: bool, flag_no_fail_fast: bool, flag_frozen: bool, @@ -56,7 +56,7 @@ Options: -v, --verbose ... Use verbose output -q, --quiet No output printed to stdout --color WHEN Coloring: auto, always, never - --message-format FMT Error format: human, json-v1 + --message-format FMT Error format: human, json [default: human] --no-fail-fast Run all tests regardless of failure --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date @@ -94,9 +94,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { &options.flag_color, options.flag_frozen, options.flag_locked)); - let message_format = try!(ops::MessageFormat::from_option( - &options.flag_message_format - )); let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())); @@ -130,7 +127,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { release: options.flag_release, mode: mode, filter: filter, - message_format: message_format, + message_format: options.flag_message_format, target_rustdoc_args: None, target_rustc_args: None, }, diff --git a/src/cargo/lib.rs b/src/cargo/lib.rs index b96da7d66..d1a8f9088 100644 --- a/src/cargo/lib.rs +++ b/src/cargo/lib.rs @@ -211,8 +211,7 @@ pub fn version() -> String { }) } -fn flags_from_args(usage: &str, args: &[String], - options_first: bool) -> CliResult +fn flags_from_args(usage: &str, args: &[String], options_first: bool) -> CliResult where T: Decodable { let docopt = Docopt::new(usage).unwrap() diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 3b88365d5..0767e9e46 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -76,23 +76,12 @@ pub enum CompileMode { Doc { deps: bool }, } -#[derive(Clone, Copy, PartialEq, Eq)] +#[derive(Clone, Copy, PartialEq, Eq, RustcDecodable)] pub enum MessageFormat { Human, Json } -impl MessageFormat { - pub fn from_option(opt: &Option) -> CargoResult { - match opt.as_ref().map(|s| s.as_ref()) { - None | Some("human") => Ok(MessageFormat::Human), - Some("json-v1") => Ok(MessageFormat::Json), - Some(other) => bail!("argument for --message-format must be human or json-v1, \ - but found `{}`", other) - } - } -} - pub enum CompileFilter<'a> { Everything, Only { diff --git a/tests/build.rs b/tests/build.rs index f30dc54f6..739a5b9c4 100644 --- a/tests/build.rs +++ b/tests/build.rs @@ -2302,7 +2302,7 @@ fn compiler_json_error_format() { .file("bar/src/lib.rs", r#"fn dead() {}"#); assert_that(p.cargo_process("build").arg("-v") - .arg("--message-format").arg("json-v1"), + .arg("--message-format").arg("json"), execs().with_json(r#" { "reason":"compiler-message", @@ -2346,9 +2346,9 @@ fn wrong_message_format_option() { p.build(); assert_that(p.cargo_process("build").arg("--message-format").arg("XML"), - execs().with_status(101) - .with_stderr_contains("\ -[ERROR] argument for --message-format must be human or json-v1, but found `XML`")); + execs().with_status(1) + .with_stderr_contains( +r#"[ERROR] Could not match 'xml' with any of the allowed variants: ["Human", "Json"]"#)); } #[test] -- 2.30.2